import type { App } from 'vue'
import { lazyLoadImage } from '@/utils/image'

export default {
  install(app: App) {
    // 图片懒加载指令
    app.directive('lazy', {
      mounted(el: HTMLImageElement, binding) {
        lazyLoadImage(el, binding.value)
      }
    })

    // 防抖指令
    app.directive('debounce', {
      mounted(el, binding) {
        let timer: NodeJS.Timeout
        el.addEventListener('click', () => {
          if (timer) {
            clearTimeout(timer)
          }
          timer = setTimeout(() => {
            binding.value()
          }, 300)
        })
      }
    })
  }
} 